<%@page import="java.util.ArrayList"%>
<%@page import="cn.sendto.model.ParkInfoModel"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="cn.sendto.service.ParkInfoService"%>
<%@page import="cn.sendto.model.CarInfoModel"%>
<%@page import="java.util.List"%>
<%@page import="cn.sendto.service.CarInfoService"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"  errorPage="../err.jsp"%>
	<jsp:include page="../lock.jsp"></jsp:include>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>车辆信息表</title>
<style >
.txt20 {
	font-size: 20px;
}

.input {
	width: 60px;
	height: 25px;
}
a{
	text-decoration: none;
}
</style>
</head>
<body>
<div class="txt20">当前位置-->查询车辆信息</div>
	<%
		request.setCharacterEncoding("UTF-8");
	
		CarInfoService cis = new CarInfoService();
		String select = request.getParameter("select");
	%>
	

	<form action="carlist.jsp" method="post">
		<span>搜索关键字：</span>&nbsp;
		<input type="text" name="select" placeholder="请输入要查询车辆关键字">
		&nbsp;&nbsp;<input type="submit" name="查询" value="查询" class="input">
	</form>
	<div align="right" style="width:95%;font-size:25px;"><a href="addcar.jsp">添加车辆信息</a></div>
	<%
	if (request.getAttribute("carinfo") != null) {
		out.print("<span style='color:red'>"+request.getAttribute("carinfo")+"</span>");
	}
		List<CarInfoModel> list = new ArrayList<CarInfoModel>();
		if (select == null ) {
			list = cis.allCar();
			out.print("目前小区共记录了车辆信息"+list.size()+"条");
		}
		if (select != null) {
			list = cis.select(select);
			out.print("查询到相关信息"+list.size()+"条");
		}
		if (list.size() > 0) {
	%>
	<div>
		<table width="95%" class="txt12" style="background-color: #00BBEE"
			cellspacing="1" cellpadding="0">
			<tr style="background-color: #EEEEEE; height: 30px">
				<th>序号</th>
				<th>车牌号</th>
				<th>车辆型号</th>
				<th>颜色</th>
				<th>业主</th>
				<th>行使证号</th>
				<th>车位信息</th>
				<th>修改</th>
				<th>删除</th>
			</tr>
			<%
				for (int i = 0; i < list.size(); i++) {
			%>
			<tr style="background-color: white; height: 25px;">
				<td align="center"><%=i + 1%></td>
				<td align="center"><%=list.get(i).getCarNum()%></td>
				<td align="center"><%=list.get(i).getCarType()%></td>
				<td align="center"><%=list.get(i).getColor()%></td>
				<td align="center"><%=cis.residentName(list.get(i).getResidentId())%></td>
				<td align="center"><%=list.get(i).getDriveNum()%></td>
				<td align="center">
					<%
						if (list.get(i).getParkId() != 0) {
									ParkInfoService pis = new ParkInfoService();
									List<ParkInfoModel> list1 = pis.park(list.get(i).getParkId());
									if (list1.size() > 0) {
										out.print(list1.get(0).getParkPosition() + "," + list1.get(0).getParkNum());
									}
								} else {
									out.print("暂无车位信息");
								}
					%>
				</td>


				<td align="center"><a href="modcar.jsp?id=<%=list.get(i).getCarId()%>" onclick="return confirm('是否修改此信息？')"><img src="../img/edit.gif"></a>

				</td>
				<td align="center"><a href="delcar.jsp?id=<%=list.get(i).getCarId()%>"><img src="../img/delimg.gif" onclick="return confirm('是否确认删除？')"></a>
				</td>
			</tr>
			<%
				}
				}
			%>
		</table>
	</div>
</body>
</html>